package com.fedorvlasov.lazylist;

import java.util.ArrayList;

import com.fedorvlasov.lazylist.LazyAdapter.ViewHolder;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import androidstore.app.data.ReviewData;

public class ReviewAdapter extends BaseAdapter {
    private Activity activity;
    private ArrayList<ReviewData> data;
    private static LayoutInflater inflater=null;
    
    public ReviewAdapter(Activity a, ArrayList<ReviewData> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public static class ViewHolder{
        public TextView name;
        public TextView date;
        public TextView comment;
        public RatingBar rating;
    }
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        ViewHolder holder;
        if(convertView==null){
            vi = inflater.inflate(R.layout.review_item, null);
            holder=new ViewHolder();
            holder.name=(TextView)vi.findViewById(R.id.name);
            holder.rating = (RatingBar)vi.findViewById(R.id.rating);
            holder.comment = (TextView)vi.findViewById(R.id.comment);
            holder.date		=	(TextView)vi.findViewById(R.id.date);
            vi.setTag(holder);
        }
        else
            holder=(ViewHolder)vi.getTag();
        
        holder.name.setText(data.get(position).CustomerName);
        holder.comment.setText(data.get(position).CommentContent);
        holder.rating.setRating((float)data.get(position).Votes);
        holder.date.setText(data.get(position).DatePost);

        return vi;
    }

}
